﻿using System;
using System.ComponentModel.DataAnnotations;

namespace assignment1
{
    class fuction
    {
        public void q1getPrime(int n,int[]primes)
        {
            int pop = 0;
            int i = 2;
            while (i <= n && n > 1)
            {
                if (n % i == 0)
                {
                    n /= i;
                    primes[pop++] = i;
                }
                else i++;
            }
        }

        public void q2caArr(int[]arr,out int max,out int min,out int average ,out int sum)
        {
            max = arr[0]; min = arr[0]; average = 0; sum = arr[0];
            for(int i = 1; i < arr.Length; i++)
            {
                if(arr[i] > max)
                {
                    max = arr[i];
                }
                else if (arr[i] < min)
                {
                    min = arr[i];
                }
                sum += arr[i];
            }
            average= sum / arr.Length;
        }

        public void q3getPrime(int[] primes)
        {
            int pop = 0; ;
            bool[] isp = new bool[100];
            for (int i = 2; i < 100; i++)
            {
                if (!isp[i]) primes[pop++] = i;
                for (int j = 0; j < pop && i * primes[j] < 100; j++)
                {
                    isp[i * primes[j]] = true;
                    if (i % primes[j] == 0) break;
                }
            }
        }

        public bool q4isToeplitz(int[,] a)
        {
            int col = a.GetLength(1);
            int row = a.GetLength(0);
            if (a.Length == 1 || col == 1) return true;
            for(int j = 0; j < col; j++)
            {
                int tem = a[0,j];
                int x = 0, y = j;
                while (++x < row && ++y < col)
                {
                    if (a[x,y] != tem) return false;
                }
            }
            for(int i = 0; i < row; i++)
            {
                int tem = a[i,0];
                int x = i, y = 0;
                while (++x < row && ++y < col)
                {
                    if (a[x,y] != tem) return false;
                }
            }
            return true;
        }
    }
    class ExecuteFunction
    {
        static void Main(string[] args)
        {
            fuction f = new fuction();

            //q1
            /* int n;
             n = int.Parse(Console.ReadLine());
             int[]arr = new int[n];
            f.q1getPrime(n, arr);
             for(int i = 0; i < arr.Count(); i++)
             {
                 if (arr[i] == 0) break;
                 Console.WriteLine(arr[i]);
             }*/


            //q2
            /*int[] arr = { 1, 2, 3, 4, 5, 6, 7, 8 };
            int max,min,average,sum;
            f.q2caArr(arr,out max,out min,out average,out sum);
            Console.WriteLine($"{max} {min} {average} {sum}");*/


            //q3
            /*int[] arr = new int[100];
            f.q3getPrime(arr);
            for(int i = 0; i < 100; i++)
            {
                if (arr[i] == 0) break;
                Console.WriteLine(arr[i]);
            }*/


            //q4
            /*int[,]a = new int[,] { { 1, 2, 3, 4 }, { 5, 1, 2, 3 },{ 9, 5, 1, 2 } };
            int[,] b = new int[,] { { 1, 2, 3, 4 }, { 5, 1, 2, 3 }, { 9, 5, 1, 3 } };
            Console.WriteLine(f.q4isToeplitz(a));
            Console.WriteLine(f.q4isToeplitz(b));*/

        }
    }
}
